package com.kk.app.render;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;


import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/**
 * @author wk
 * @date 2024/12/5 16:40
 * @describe
 */
public class SurfaceViewRender implements GLSurfaceView.Renderer {
    private static final String TAG = "[SurfaceViewRender]";
    private ISurfaceRenderListener mISurfaceRenderListener;

    public void setSurfaceRenderListener(ISurfaceRenderListener ISurfaceRenderListener) {
        mISurfaceRenderListener = ISurfaceRenderListener;
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        if (mISurfaceRenderListener != null) {
            mISurfaceRenderListener.onSurfaceCreated(gl, config);
        }
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        if (mISurfaceRenderListener != null) {
            mISurfaceRenderListener.onSurfaceChanged(gl, width, height);
        }
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        if (mISurfaceRenderListener != null) {
            mISurfaceRenderListener.onDrawFrameBegin(gl);
        }
        if (mISurfaceRenderListener != null) {
            mISurfaceRenderListener.onDrawFrame(gl);
        }

        if (mISurfaceRenderListener != null) {
            mISurfaceRenderListener.onDrawFrameEnd(gl);
        }
    }
}
